package com.ruoyi.common.core.utils;

import com.ruoyi.common.core.utils.ip.IpUtils;

import javax.servlet.http.HttpServletRequest;

public class HttpRequestUtil {

    //获取ip地址
    public static String getIpAddr() {
        HttpServletRequest request = ServletUtils.getRequest();
        return IpUtils.getIpAddr(request);
    }

    //获取ip地址
    public static String getAddr() {
        HttpServletRequest request = ServletUtils.getRequest();
        return IpUtils.getAddr(request);
    }


    //获取浏览器信息
    public static String getBrowser() {

        HttpServletRequest request = ServletUtils.getRequest();
        String browserType = "未知";
        String ua = request.getHeader("user-agent").toLowerCase();
        if (ua.indexOf("MSIE".toLowerCase()) > 0 || ua.indexOf("Trident".toLowerCase()) > 0 || ua.indexOf("Edge".toLowerCase()) > 0) {
            browserType = "Ie";
        } else if (ua.indexOf("Firefox".toLowerCase()) > 0) {
            browserType = "Firefox";
        } else if (ua.indexOf("Opera".toLowerCase()) > 0) {
            browserType = "Opera";
        } else if (ua.indexOf("Chrome".toLowerCase()) > 0) {
            browserType = "Chrome";
        } else if (ua.indexOf("Safari".toLowerCase()) > 0) {
            browserType = "Safari";
        }
        return browserType;
    }

    //获取系统
    public static String getOs() {
        HttpServletRequest request = ServletUtils.getRequest();
        String osStr = "未知";
        String ua = request.getHeader("user-agent").toLowerCase();
        //这里就简单判断下
        if (ua.contains("Windows".toLowerCase())) {
            osStr = "Windows";
        } else if (ua.contains("Linux".toLowerCase())) {
            osStr = "Linux";
        } else {

        }

        return osStr;
    }
}
